import request, { type ListQuery, type ListResponse } from "@/utils/request";
import { type SupplierItemType } from "./supplier";
import { type MerchantType } from "../merchant/merchant";

const SUPPLIER_ACCOUNT_BASE_URL = "/api";

export const SupplierAccountApi = {
  getSupplierAccountList: (params: ListQuery) => {
    return request.get<any, ListResponse<SupplierAccountItemType>>(
      `${SUPPLIER_ACCOUNT_BASE_URL}/internal/SupplierAccount/`,
      { params }
    );
  },
  getSupplierAccountDetail: (id: number) => {
    return request.get<any, SupplierAccountItemType>(
      `${SUPPLIER_ACCOUNT_BASE_URL}/internal/SupplierAccount/${id}/`
    );
  },
  addSupplierAccount: (data: Partial<SupplierAccountForm>) => {
    return request.post(`${SUPPLIER_ACCOUNT_BASE_URL}/internal/SupplierAccount/`, data, {
      headers: {
        "Content-Type": "multipart/form-data",
      },
    });
  },
  updateSupplierAccount: (data: Partial<SupplierAccountForm>) => {
    return request.put(`${SUPPLIER_ACCOUNT_BASE_URL}/internal/SupplierAccount/${data.id}/`, data, {
      headers: {
        "Content-Type": "multipart/form-data",
      },
    });
  },
  deleteSupplierAccount: (id: number | string) => {
    return request.delete(`${SUPPLIER_ACCOUNT_BASE_URL}/internal/SupplierAccount/${id}/`);
  },
};

export type SupplierAccountListQuery = {} & ListQuery;

export type SupplierAccountStatus = "freeze" | "normal" | "completed";

export type SupplierAccountItemType = {
  id: number | string;
  supplier: SupplierItemType;
  merchant: MerchantType;
  created_at: string;
  updated_at: string;
  is_active: boolean;
  code: string;
  amount: string;
  status: SupplierAccountStatus;
};

export type SupplierAccountForm = {
  id?: number | string;
  supplier?: number;
  merchant?: number;
  is_active: boolean;
  code: string;
  amount: string;
  status: SupplierAccountStatus;
};

export default SupplierAccountApi;
